"""Header_Information
------------------------------------
    File_Name: exceptions_handlers
    Author: RR9
    Date: 2024/09/26
    Description: 自定义异常
------------------------------------
"""

from fastapi import Request, responses
from app import app


class CustomException(Exception):
    def __init__(self, message: str):
        self.message = message


@app.exception_handler(CustomException)
async def custom_exception_handler(request: Request, exc: CustomException):
    """自定义全局异常处理"""
    return responses.JSONResponse(
        status_code=499,
        content={"message": f"99999-- {exc.message} --999999; request: {request.url}"}
    )
